package com.esri.core.internal.tasks.a;

import com.esri.core.geometry.SpatialReference;
import java.io.IOException;
import java.io.StringWriter;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;

/* loaded from: classes.dex */
public class a extends com.esri.core.internal.tasks.f {
    private static final long serialVersionUID = 1;
    public List<Map<String, String>> a;
    public SpatialReference b = null;

    @Override // com.esri.core.internal.tasks.f
    public boolean validate() {
        return true;
    }

    @Override // com.esri.core.internal.tasks.f
    public Map<String, String> generateRequestParams() throws Exception {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("addresses", a());
        SpatialReference spatialReference = this.b;
        if (spatialReference != null) {
            linkedHashMap.put("outSR", String.valueOf(spatialReference.getID()));
        }
        return linkedHashMap;
    }

    private String a() throws JsonGenerationException, IOException {
        if (this.a == null) {
            return null;
        }
        int i = 0;
        StringWriter stringWriter = new StringWriter();
        JsonGenerator a = com.esri.core.internal.util.d.a(stringWriter);
        a.writeStartObject();
        a.writeArrayFieldStart("records");
        for (Map<String, String> map : this.a) {
            a.writeStartObject();
            a.writeFieldName("attributes");
            a.writeStartObject();
            a.writeFieldName("OBJECTID");
            if (!map.containsKey("OBJECTID")) {
                a.writeNumber(i);
                i++;
            } else {
                a.writeNumber(Integer.parseInt(map.get("OBJECTID")));
            }
            for (String str : map.keySet()) {
                if (!"OBJECTID".equalsIgnoreCase(str)) {
                    a.writeFieldName(str);
                    a.writeString(map.get(str));
                }
            }
            a.writeEndObject();
            a.writeEndObject();
        }
        a.writeEndArray();
        a.writeEndObject();
        a.close();
        return stringWriter.toString();
    }
}
